/***************************************************************************
 *   sbx.c                                                                 *
 *   Created on 9 wrzesień 2009, 10:54                                     *
 *   Copyright (C) 2009 by cmaster.matso (Maciej Kadłubowski)              *
 *   cmaster.matso@gmail.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "sbx.h"

/**
 *
 */
int gsubReadSBXModel(const char *filename, char *sbx[6]) {
    FILE *fp;
    int i = 0;

    fp = fopen(filename, "r");
    if (!fp) {
        MGPI_PostMessagef("readSBXModel: couldn't open \"%s\"", filename);
        return 0;
    }

    while(i < 6) {
        sbx[i] = (char *)calloc(128, sizeof(char));
        sbx[i] = fgets(sbx[i], 128, fp);
        ++i;
    }

    fclose(fp);
    return (!0);
}

/**
 *
 */
int gsubFreeSBXModel(char *sbx[6]) {
    int i = 0;
    
    if (sbx) {
        while(i < 6 && sbx[i]) {
            free(sbx[i]);
            ++i;
        }
    }

    free(sbx);

    return (!0);
}
